<template>
	<div class="allcontainer" v-loading="loading">
		<div class="h2">学生组织成员管理</div>
		<div class="bg-white">
			<div id="components-form-demo-advanced-search">
				<a-form class="ant-advanced-search-form home-form" :form="form" @submit="handleSearch">
					<a-row :gutter="24">
						<a-col :span="8">
							<a-form-item label="关键字">
								<a-input class="field-right" placeholder="请输入姓名/学号搜索" v-decorator="[`key`]" />
							</a-form-item>
						</a-col>
						<a-col :span="16">
							<a-button type="primary" html-type="submit" class="btn1">搜索</a-button>
							<a-button @click="handleReset" class="btn2">重置</a-button>
							<a-button v-if="showbutton" type="primary" class="btn" @click="addList">邀请成员</a-button>
						</a-col>
					</a-row>
				</a-form>
			</div>
			<div class="table">
				<el-table stripe ref="singleTable" :data="data" highlight-current-row style="width: 100%">
					<el-table-column type="index" label="序号" width="60" fixed="left" align="center"></el-table-column>
					<el-table-column prop="Name" label="姓名/学号" min-width="160" fixed="left" align="center">
						<template slot-scope="scope">
							{{ scope.row.Name | testname }} / {{ scope.row.UserNo | testno }}
							<a-tag color="pink" v-if="scope.row.IsManager==true"> 管理员 </a-tag>
						</template>
					</el-table-column>
					<el-table-column prop="AddTime" label="加入时间" min-width="100" align="center"></el-table-column>
					<el-table-column prop="IsEnable" label="操作" width="245" fixed="right" v-if="showbutton">
						<template slot-scope="scope">
							<div class="user-btn user-btn-auto">
								<span class="detail" v-if="scope.row.IsManager && ChairmanNo == UserInfo.UserNo" @click="detail(scope.row,1)">详情</span>
								<span class="delete" v-if="!scope.row.IsManager" @click="deletemember(scope.row)">删除</span>
								<span class="modify" v-if="scope.row.IsManager && ChairmanNo == UserInfo.UserNo" @click="detail(scope.row,2)">修改权限</span>
								<span class="setup" v-if="!scope.row.IsManager && ChairmanNo == UserInfo.UserNo" @click="detail(scope.row,3)">设为管理员</span>
								<span class="cancel" v-if="scope.row.IsManager && ChairmanNo == UserInfo.UserNo" @click="canceladmin(scope.row,4)">取消管理员</span>
							</div>
						</template>
					</el-table-column>
				</el-table>
			</div>
		</div>
		<detail :approvalType="4" :text="text" v-show="showModal" @closeFun="closeFun"></detail>
		<invitation :ID="ClubID" v-show="invitationShow" @closeFun="closeFun"></invitation>
	</div>
</template>

<script>
	import Func from '@/utils/func';
	import Cache from '@/utils/cache'
	import {
		GetUserClubMember,
		DeleteClub,
		EnableClub,
		GetClubTypeList,
		GetDepartList,
		DoDeleteUserClubMember,
		DoAddUserClubMember,
		DoDeleteUserClubAdmin,
		UserGetClubDetail
	} from '@/api/follow';
	import detail from './detail'
	import invitation from './InvitationClub'
	const data = [];
	export default {
		components: {
			detail,
			invitation
		},
		data() {
			return {
				data,
				form: this.$form.createForm(this, {
					name: 'advanced_search'
				}),
				pagination: {
					currentPage: 1,
					pageSize: this.global.pageSize,
					pageSizeOptions: this.global.pageSizeOptions, // 每页中显示的数据
					showTotal: total => `共有 ${total} 条数据` // 分页中显示总的数据
				},
				addIf: false,
				text: {},
				visible: false,
				confirmLoading: false,
				itemId: '',
				departmentList: [],
				worklist: [],
				loading: false,
				values: {},
				pages: {
					pageIndex: 1,
					pageSize: 20
				},
				tableHeight: parseFloat(window.innerHeight - 160),
				TypeIDList: [],
				DepartCodeList: [],
				ProjectIDList: [],
				ishaveid: true,
				selectList: {},
				showModal: false,
				UserInfo: Cache.get('myInfo'),
				ChairmanNo: this.$route.query.ChairmanNo,
				linktype: 1,
				ClubID: this.$route.query.ID,
				visible: false,
				deletelist: {},
				time: '',
				invitationShow: false,
				managerPower: '',
				ChairmanNo: '',
				thisChairmanNo: Cache.get('myInfo').UserNo,
				showbutton: false
			};
		},
		computed: {},
		created() {
			this.getList();
			this.getOtherList()
		},
		mounted() {},
		methods: {
			canceladmin(text) {
				let that = this
				this.$confirm({
					title: '提示',
					content: `您确定取消该用户的管理员权限吗？`,
					okText: '确认',
					cancelText: '取消',
					async onOk() {
						let data = {}
						data.userNo = text.UserNo
						data.clubID = that.ClubID
						let res = await DoDeleteUserClubAdmin(data);
						if (res.data.code == 0) {
							that.getList()
							that.$message.success(res.data.msg)
						} else {
							that.$message.error(res.data.msg)
						}
					}
				})
			},
			handleCancel(e) {
				this.visible = false
				this.getList()
			},
			deletemember(text) {
				// this.visible = true
				// this.deletelist = text
				let that = this
				this.$confirm({
					title: '提示',
					content: `您确定删除该用户吗？`,
					okText: '确认',
					cancelText: '取消',
					async onOk() {
						let data = {}
						data.id = text.ID
						let res = await DoDeleteUserClubMember(data);
						if (res.data.code == 0) {
							that.getList()
							that.$message.success(res.data.msg)
						} else {
							that.$message.error(res.data.msg)
						}
					}
				})
			},
			detail(text, type) {
				this.text = {
					...text,
					linktype: type,
					time: new Date(),
					ID: this.ClubID
				}
				this.showModal = true
			},
			handleChange(val) {
				this.currentRow = val;
				if (val.ID) {
					this.ishaveid = false
					this.selectList = val
				} else {
					this.ishaveid = true
				}
			},
			handleSearch(e) {
				e.preventDefault();
				this.form.validateFields((error, values) => {
					this.pagination.currentPage = 1;
					this.values = values;
					this.getList();
				});
			},
			handleReset() {
				this.form.resetFields();
				this.values = {};
				this.getList();
			},
			handleSizeChange(val) {
				this.pagination.pageSize = val;
				this.getList();
			},
			handleCurrentChange(val) {
				this.pagination.currentPage = val;
				this.getList();
			},
			async getList() {
				this.loading = true;
				let data = {};
				if (this.values) {
					data = this.values;
				}
				data.clubID = this.$route.query.ID
				data.pageIndex = this.pagination.currentPage;
				data.pageSize = this.pagination.pageSize;
				let res = await GetUserClubMember(data);
				this.loading = false;
				this.data = res.data.data;
			},
			async getOtherList() {
				let data = {}
				data.id = this.$route.query.ID
				data.UserNo = this.$route.query.ChairmanNo
				let res3 = await UserGetClubDetail(data)
				this.managerPower = res3.data.managerPower
				this.ChairmanNo = res3.data.data.ChairmanNo
				if (this.ChairmanNo == this.thisChairmanNo) {
					this.showbutton = true
				} else if (this.managerPower != null) {
					if (this.managerPower.IsAgreeManageMember == true) {
						this.showbutton = true
					} else {
						this.showbutton = false
					}
				}
				// if(this.managerPower!=null){
				// 	if(this.managerPower.IsAgreeManageMember==true){
				// 		this.showbutton=true
				// 	}else{
				// 		this.showbutton=false
				// 	}
				// }else if(this.ChairmanNo==this.thisChairmanNo){
				// 	this.showbutton=true
				// }else{
				// 	this.showbutton=false
				// }
			},
			addList() {
				this.invitationShow = !this.invitationShow;
			},
			modifyList(text) {
				text = Object.assign(text, {
					time: new Date()
				});
				this.addIf = !this.addIf;
				this.text = text;
			},
			closeFun(index) {
				this.showModal = false
				this.invitationShow = false
				if (index == 1) {
					this.getList()
				}
			},
		}
	};
</script>

